<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 租户 服务控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\TenantService;
use think\Request;
use think\Response;

class TenantController extends VerifyController
{
    protected $tenantService;

    /**
     * ContractTemplateController constructor.
     */
    public function __construct()
    {
        parent::__construct();
        $this->tenantService = TenantService::getInstance();
    }

    /**
     * 查询租户认证信息
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function getAuthenticationInfo(Request $request)
    {
        $res = $this->tenantService->getAuthenticationInfo($request->getTenantId(), $request->param());
        return json(success_response("", $res));
    }

    /**
     * 查询部门成员
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function selectDepartmentUser(Request $request)
    {
        $res = $this->tenantService->selectDepartmentUser($request->getTenantId(), $request->param());
        return json(success_response("", $res));
    }

    /**
     * 查询部门成员
     * @param Request $request
     * @return Response
     * @throws \Exception
     */
    public function selectDepartmentUserTree(Request $request)
    {
        $res = $this->tenantService->selectDepartmentUserTree($request->param());
        return json(success_response("", $res));
    }

    /**
     * 从租户移除
     * @param Request $request
     * @return Response
     */
    public function removeTenantUser(Request $request)
    {
        $param = $request->param()['param'];
        $tenantId = $param['tenant_id'];
        $unionId = $param['user_id'];
        $res = $this->tenantService->removeTenantUser($unionId, $tenantId);
        return json(success_response("", $res));
    }
}
